#include "widget.h"
#include "ui_widget.h"

void Widget::handleShortCutAdd()
{
    int value = ui->horizontalSlider->value();
//    if(value == ui->horizontalSlider->maximum())
//        return;
    ui->horizontalSlider->setValue(value + 5);
}

void Widget::handleShortCutSub()
{
    int value = ui->horizontalSlider->value();
//    if(value < ui->horizontalSlider->minimum())
//        return;
    ui->horizontalSlider->setValue(value - 5);
}

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->horizontalSlider->setMaximum(100);

    ui->label->setText("the number is 0");

    QShortcut* shortCutAdd = new QShortcut(this);
    shortCutAdd->setKey(QKeySequence("="));

    QShortcut* shortCutSub = new QShortcut(this);
    shortCutSub->setKey(QKeySequence("-"));

    connect(shortCutAdd,&QShortcut::activated,this,&Widget::handleShortCutAdd);
    connect(shortCutSub,&QShortcut::activated,this,&Widget::handleShortCutSub);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setText("the number is " + QString::number(value));
}
